//
//  NSString+RCRSA.m
//  StructToolsDemo
//
//  Created by 杨晓辉 on 2017/8/23.
//  Copyright © 2017年 杨晓辉. All rights reserved.
//

#import "NSString+RCRSA.h"
#import "NSData+RCRSA.h"
@implementation NSString (RCRSA)
+ (NSString *)publicKeyEncryptRSAWithString:(NSString *)string
{
    NSData * data = [NSData publicKeyEncryptRSAWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    data = [data base64EncodedDataWithOptions:0];
    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return result;

}

+ (NSString *)privateKeyDecryptRSAWithString:(NSString *)string
{
    NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];
    
    NSData *decryptData = [NSData privateKeyDecryptRSAWithData:data];
    
    NSString* result = [[NSString alloc] initWithData: decryptData encoding:NSUTF8StringEncoding];
    return result;

}


#pragma mark ---私钥加密 公钥解密--




+ (NSString *)privateKeyEncryptRSAWithString:(NSString *)string
{
    NSData *data = [NSData privateKeyEncryptRSAWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    data = [data base64EncodedDataWithOptions:0];
    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return result;

}



+ (NSString *)publicKeyDecryptRSAWithString:(NSString *)string
{
    NSData *data = [[NSData alloc] initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];
    data = [NSData publicKeyDecryptRSAWithData:data];
    NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    return result;

}
@end
